package com.livsdesign.tools.condition

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.snackbar.Snackbar
import com.livsdesign.tools.R

/**
 * 需求是：
 * 1. 某个页面置顶
 * 2. 某个区域替换
 * 3. 全局置顶
 */
class ConditionFragment : Fragment(R.layout.fragment_condition) {

    private val viewModel: ConditionViewModel by lazy {
        ViewModelProvider(viewModelStore, ViewModelProvider.NewInstanceFactory()).get(
            ConditionViewModel::class.java
        )
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val titleTx = view.findViewById<TextView>(R.id.titleTx)

        viewModel.countLiveData.observe(viewLifecycleOwner) {
            listening()
        }
    }

    private fun listening() {
        for (target in viewModel.getTargets()) {
            target.template.apply {
                if (!mState.hasObservers()) {
                    mState.observe(viewLifecycleOwner) {

                    }
                }
            }
        }
    }


}